package cn.weiyang.controller;

import cn.weiyang.model.Result;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 * Created by Administrator on 2017/7/27.
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result<?> handleException(Exception e){
        /*这句代码能打出具体的异常类型*/
        /*e.printStackTrace();*/
        if(e instanceof BindException){
            Result<Void> result=new Result<Void>();
            result.setCode(Errcode.Gl_SYS_ARG_INVALID.code);
            result.setMsg(Errcode.Gl_SYS_ARG_INVALID.msg);
            return result;
        }
        return null;
    }

}
